<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\admin\model;
use think\Model;
use think\facade\Db;

class Navigation extends Model{
    /**列表
    * lang 语言
    * signid 1显示9已删除，大于9就是删除时间戳
    * client 客户端，pc电脑端，wap移动端，app小程序APP端
    * keyword 关键词
    * order 排序
    */
	static function index($lang,$signid,$client,$keyword,$order){
		$keyword = trim($keyword);
		$where[] = ['lang','=',$lang];
		if(!empty($client) and $signid <> 9){
			$clientWhere = 'find_in_set(\''.$client.'\',client)';
		}else{
			$clientWhere[] = ['id','>',0];
		}

		if($signid > 8){//已软删除
			$where[] = ['signid','>','8'];
		}else{
			$where[] = ['signid','=',$signid];
		}

		$rs = Db::name('navigation')->where($where)->where($clientWhere)->where('title','like',"%$keyword%")->order($order)->select();
		if($signid <>9) $rs = getChildSort($rs);
		return $rs;
	}

    //客户端
    protected function setClientAttr(){
		$client = '';
		$client_array=input('client/a');
        for($i=0;$i<count($client_array);$i++){
			$i<count($client_array)-1 ? $client.=$client_array[$i]."," : $client.=$client_array[$i];
	    }
		return $client;
    }
	
    //新增编辑
	static function edit($id){
	    if($id>0){//编辑
			$navigation = Navigation::find($id);
		}else{//新增
			$navigation = new Navigation;
		}
		$navigation->save(input('post.'));
		return $navigation->id;
	}
}